﻿using SIG.Model.Store;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace SIG.Model.Mapping
{
    public class CartMap: EntityTypeConfiguration<Cart>
    {
        public CartMap()
        {
            this.HasKey(p => p.Id);
            this.ToTable("CartSet");
            this.Property(p => p.Id)
                .HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(p => p.GoodsId).IsRequired();
            this.Property(p => p.CartId).IsRequired();
            this.Property(p => p.Count).IsRequired();
            this.Property(p => p.DateCreated).IsOptional().HasColumnType("datetime");

            this.HasRequired(p => p.Goods)
              .WithMany(h => h.Carts)
              .HasForeignKey(p => p.GoodsId);

                

     }
   }
}
